import { Flex, WhiteSpace } from 'weaver-mobile';
import React from 'react'
import { Tools,Button } from 'weaver-mobile';
import { withRouter } from 'react-router-dom';
const getLabel = Tools.getLabel;

@withRouter
export default class FnaInvoiceComponent extends React.Component {

    componentDidMount() {
        const queryParams = this.transQueryParams(this.props.location);
        if(queryParams.customParameterRequestor == 'xiaoe'?true:false){
            this.refs.open.props.onClick();
        }

        

        window.goBackfna = this.goBackfna;
        window.getWfId = this.getWfId;
        window.getWfDetailName = this.getWfDetailName;
    }

	constructor(props) {
        super(props);
        const {} = this.props;
	}

    render() {
        const {symbol} = this.props;
        const {beStandard,invoiceCloud = false} = this.props.fnaInfo;
        // console.log('+++++this.props',this.props.wfLayoutStore.baseParam)
        return (
            <div> 
                {!invoiceCloud && 
                    <Flex>
                        <Flex.Item>
                            <Button 
                                ref='open'
                                style={{'border-radius': '4px','font-size':'12px','padding':'0 5px'}} 
                                size={"small"} type={'primary'} 
                                onClick = {
                                    () => {
                                        // this.props.history.push("/req/fnaInvoiceScanning" + "?symbol=" + symbol)
                                        window.showHoverWindow(`/mobile/plugin/1/invoices_em7.html?em_auth_code=1&WfDetailName=${symbol}`,'/req',false,true)
                                    }
                                }>
                                {getLabel(501097,"发票识别")}
                            </Button>  
                        </Flex.Item>
                        {beStandard && <Flex.Item>
                            <Button 
                                style={{'border-radius': '4px','font-size':'12px','padding':'0 5px'}} 
                                size={"small"} 
                                type={'primary'} 
                                // onClick={()=>{this.props.history.push("/req/fnaInvoiceScanning?fna_xiaoe=1")}}>
                                onClick={()=>{window.showHoverWindow('/mobile/plugin/1/invoices_em7_new.html','/req',false,true)}}>
                                {getLabel(131529,"发票导入")}
                            </Button>
                        </Flex.Item>}
                    </Flex>
                }
                {
                    invoiceCloud && 
                    <Flex>
                        <Flex.Item>
                            <Button 
                                style={{'border-radius': '4px','font-size':'12px','padding':'0 5px'}} 
                                size={"small"} 
                                type={'primary'} 
                                onClick={()=>{this.props.history.push("/req/fnaInvoiceScanning?invoiceCloud="+invoiceCloud+"&symbol="+symbol)}}>
                                {getLabel(516434,"我的票夹")}
                            </Button>
                        </Flex.Item>
                    </Flex>
                }
            </div>
        )
    }

    //url参数串转成对象
    transQueryParams = (arg) => {
        let paramStr = typeof arg === "object" ? arg.search : arg;
        if(paramStr.indexOf("?") > -1)
            paramStr = paramStr.substring(paramStr.indexOf("?")+1);
        let queryParams = {};
        const arr = paramStr.split("&");
        arr && arr.map(item => {
            const single = item.split("=");
            queryParams[single[0]] = single[1];
        });
        return queryParams;
    }

   //获取表单的按钮组
   getFormButton = () => {
    const { history }= this.props ;
    let buttonGroupData = [
      {
        key: 'clear',
        text: getLabel(31129,'取消'),
        onClick: () => {history.go(-1)},
      }
    ];

    return buttonGroupData;
  }

  //关闭
  goBackfna = () => {
    const { history }= this.props;
    history.go(-1);
    //window.WfForm.addDetailRow("detail_1");
  }

  //获取流程ID 
   getWfId = () => {
     const {commonParam} =this.props;
     console.log('*-----------this.props',this.props);
     console.log('commonParam',commonParam);
     return commonParam.workflowid;
   }

  //获取流程明细表名
   getWfDetailName = () => {
    const {symbol} =this.props;
    console.log('symbol',symbol);
     return symbol;

   }    
}